<?php
	require("libraries/student.php");
  	class Goldtime extends Student{
		public function __construct(){
			parent::__construct();
			$this->load->helper("url");
			$this->load->helper("form");
			$this->load->library("form_validation");
			$this->load->model("model_gold");			
		}
        public function index(){
            $config['base_url'] = base_url().'admin/goldtime/index/';
            $config['total_rows'] = $this->model_gold->count_all();
            $config['per_page'] = 10;
            $config['uri_segment'] = 4;
            $this->load->library("pagination");
            $this->pagination->initialize($config);
            $start = $this->uri->segment(4);
            $data['title']="Order promotion";
            $data['data']['info']= $this->model_gold->listorder($config['per_page'],$start);
            $data['template'] = "goldhave/list_order";
            $this->load->view("layout",$data);
        }
        public function order_view(){
            $data['title'] = "Đơn đặt hàng của khách hàng";
            $data['template'] = "goldhave/order_view";
            $data['data'] = "";
            $data['all'] = $this->model_gold->order_view($this->uri->segment(4));
            $this->load->view("layout",$data);
        }
        public function del(){
            $id = $this->uri->segment(4);
            $this->model_gold->del($id);
            redirect(base_url()."admin/goldtime");
        }
        public function active(){
            $id   	= $this->uri->segment(4);
            $status	= $this->uri->segment(5);
            $db = array(
                "call_status" => $status
            );
            $this->model_gold->update_status($db,$id);
            redirect(base_url()."admin/goldtime/");
        }
		public function update(){
			$id = $this->uri->segment(4);
			$data['title']="Have us call you";
			$data['act'] = 0;
			$data['data']['info']= $this->model_gold->getdata($id);
			$data['template'] = "goldtime/edit_gold";
			if($this->input->post("ok") != ""){
				$db = array(
					"gold_type1"	=> $this->input->post("gold_type1"),
					"gold_type2"	=> $this->input->post("gold_type2"),
					"gold_type3"	=> $this->input->post("gold_type3"),
					"gold_type4"	=> $this->input->post("gold_type4"),
					"gold_type1_total"	=> $this->input->post("gold_type1"),
					"gold_type2_total"	=> $this->input->post("gold_type2"),
					"gold_type3_total"	=> $this->input->post("gold_type3"),
					"gold_type4_total"	=> $this->input->post("gold_type4"),
					"gold_status"	=> $this->input->post("number")
				);
				$this->model_gold->update($db,$id);
				redirect(base_url()."admin/goldtime");
			}else{
				$this->load->view("layout",$data);
			}
		}
		public function status(){
			$id = "1";
			$data['title']="Cập nhật giờ vàng";
			$data['act'] = 0;
			//$data['data']['info']= $this->model_gold->getdata($id);
			$data['template'] = "goldtime/edit_gold";
			if($this->input->post("ok") != ""){
				$status = $this->input->post("checkbox");
				if($status != 1){ $status = 0;}
				$db = array(
					"gold_status"	=> $status
				);
				$this->model_gold->update($db,$id);
				redirect(base_url()."admin/goldtime");
			}else{
				$this->load->view("layout",$data);
			}
		}
	}